package com.youfang.sixthmedia.ui.searcher;

import com.gzit.common.async.AsynCallback;
import com.gzit.utils.AndroidUtils;
import com.youfang.sixthmedia.common.YoufangContext;
import com.youfang.sixthmedia.message.HousefilterRequest;
import com.youfang.sixthmedia.message.HousefilterResponse;
import com.youfang.sixthmedia.net.Net;
import com.youfang.sixthmedia.net.Response;

import android.app.Activity;

public abstract class BaseSearcherActivity extends Activity {

	protected abstract void onHousefilterLoaded(HousefilterResponse r);

	public boolean needReload() {

		return YoufangContext.getCity().cityid != YoufangContext
				.getSearcherFilter().getCityId();

	}

	public void remoteLoadHousefilter() {

		HousefilterRequest req = new HousefilterRequest();
		req.setCityid(YoufangContext.getCity().cityid);

		Net.doHttpRemote(this, req, new HousefilterResponse(),
				new AsynCallback<Response>() {

					@Override
					public void callback(Response r) {
						if (!r.isOk()) {
							AndroidUtils.toastShort("加载楼盘过滤条件失败");
							return;
						}
						HousefilterResponse resp = (HousefilterResponse) r;
						resp.setBoundCityId(YoufangContext.getCity().cityid);
						YoufangContext.setSearcherFilter(resp);
						onHousefilterLoaded(resp);

					}

				});

	}
}
